package com.anzhen.springboot.activemq.queue;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.jms.JMSException;
import javax.jms.Queue;

/**
 * Created by zhenan on 2017-3-8.
 */
@Component
public class Producer {
    private int a = 0;
    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Autowired
    private Queue queue;

    @Scheduled(fixedDelay=1000)//每3s执行1次
    public void send() throws JMSException {
        System.out.println("queue:" + queue.getQueueName() + " send : 发送了第" + a + "个消息");
        this.jmsMessagingTemplate.convertAndSend(this.queue, "queue:" + queue.getQueueName() + " send : 第" + a + "个消息");
        a++;
    }
}
